#include "ChatServer.hpp"
#include <functional>
using namespace std::placeholders;
ChatServer::ChatServer(muduo::net::EventLoop *loop,
                       const muduo::net::InetAddress &iNetAddress,
                       const std::string &name)
    : _loop(loop), _tcpServer(loop, iNetAddress, name)
{
    // 注册链接事件的回调函数
    _tcpServer.setConnectionCallback(std::bind(&ChatServer::OnConnection, this, _1));
    // 注册IO事件的回调函数
    _tcpServer.setMessageCallback(std::bind(&ChatServer::OnMessage, this, _1, _2, _3));

    _tcpServer.setThreadNum(4);
};

// 将start添加到epoll关系事件中
void ChatServer::start()
{
    _tcpServer.start();
}

void ChatServer::OnConnection(const muduo::net::TcpConnectionPtr &conn)
{
}

void ChatServer::OnMessage(const muduo::net::TcpConnectionPtr &conn,
                           muduo::net::Buffer *buffer,
                           muduo::Timestamp time)
{
    std::string buf = buffer->retrieveAllAsString();
    //将json反序列一下,注意 通过json对象序列化为string对象，反序列化就应该会到json对象这个状态
    json recv = json::parse(buf); 
    //使用recv的收到的 “Message id” 调用相应的回调函数 
}
